package cn.dao.imp;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.dao.OrdergoodsDao;
import cn.entity.Ordergoods;
import cn.entity.User;

public class OrdergoodsDaoImp extends HibernateDaoSupport implements
		OrdergoodsDao {

	@Override
	public void insert(Ordergoods ordergoods) {
		getHibernateTemplate().save(ordergoods);

	}

	@Override
	public void delete(Ordergoods ordergoods) {
		getHibernateTemplate().delete(ordergoods);

	}

	@Override
	public void update(Ordergoods ordergoods) {
		getHibernateTemplate().update(ordergoods);

	}

	@Override
	public List getAll() {
		return getHibernateTemplate().find("from Ordergoods");
	}

	@Override
	public List query(Ordergoods ordergoods) {
		return getHibernateTemplate().findByExample(ordergoods);
	}

	@Override
	public Ordergoods getOrdergoodsById(Integer id) {
		return getHibernateTemplate().get(Ordergoods.class, id);
	}

	//根据订单id获取该订单id关联的所有商品快照
	@Override
	public List getOrdergoodsByOrderId(Integer id) {
		return getHibernateTemplate().find("from Ordergoods where orders.id="+id);
	}

	//根据卖家获取商品快照
	@Override
	public List<Ordergoods> getOrdergoodsBySeller(User user) {
		return getHibernateTemplate().find("from Ordergoods where user="+user.getId());
	}

}
